using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using Dll.Essences;

namespace Dll.DAL
{
    public class UserTypeDAL
    {
        public static List<UserType> GetAllUserType()
        {
            List<UserType> l = new List<UserType>();
            UserType uT;
            DataTable dt = new DataTable();
            //OleDbConnection connect = new OleDbConnection(ConfigurationManager.ConnectionStrings["base"].ConnectionString);
            OleDbConnection connect = BasePath.connect;
            OleDbCommand command = new OleDbCommand();
            command.Connection = connect;
            command.CommandText = "select *from UserType";
            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
            adapter.Fill(dt);
            DataTableReader dr = dt.CreateDataReader();
            while (dr.Read())
            {
                uT = new UserType();
                uT.Id = Convert.ToInt32(dr.GetValue(0));
                uT.Name = dr.GetValue(1).ToString();
                l.Add(uT);
            }
            return l;
        }

        public static UserType GetUserTypeByID(int id)
        {
            UserType uT = new UserType();
            DataTable dt = new DataTable();
            //OleDbConnection connect = new OleDbConnection(ConfigurationManager.ConnectionStrings["base"].ConnectionString);
            OleDbConnection connect = BasePath.connect;
            OleDbCommand command = new OleDbCommand();
            command.Connection = connect;
            command.CommandText = "select *from UserType where id=@id";
            command.Parameters.AddWithValue("@id", id);
            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
            adapter.Fill(dt);
            DataTableReader dr = dt.CreateDataReader();
            while (dr.Read())
            {
                uT.Id = Convert.ToInt32(dr.GetValue(0));
                uT.Name = dr.GetValue(1).ToString();
            }
            return uT;
        }
    }
}
